﻿#include "MaterialPlasticWidget.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaMaterialPlastic.h"
#include "ui_MaterialPlasticWidget.h"
#include <QCloseEvent>
#include <QMenu>
#include <QMessageBox>
#include <QFont>
#include <QListView>

namespace GUI
{
    MaterialPlasticWidget::MaterialPlasticWidget(EventOper::ParaWidgetInterfaceOperator * oper,Interface::FITKAbaMaterialPlastic* item, QWidget* parent) :
        _materialItem(item), MaterialWidgetBase(oper,parent), _ui(new Ui::MaterialPlasticWidget)
    {
        _ui->setupUi(this);

        initUi();
    }

    MaterialPlasticWidget::~MaterialPlasticWidget()
    {
        if (_ui != nullptr)delete _ui;
    }

    bool MaterialPlasticWidget::checkValue()
    {
//        auto checkValue = [=](QString str, int row, int column)->bool {
//            //判断数据是否有效
//            bool isOk = false;
//            str.toDouble(&isOk);
//            if (isOk == true)return true;

//            QString message = QString(tr("Tabular data for at least one option or suboption\n has either blank or zero valued row(s).\n"));
//            message = message + QString(tr("Error: Plastic row: %1\n").arg(row + 1));
//            message = message + QString(tr("Error: Plastic column: %1\n").arg(column + 1));
//            QMessageBox::warning(this, tr("FastSimApp"), message);
//            return true;
//        };

        int typeIndex = _ui->comboBox_Hardening->currentIndex();
        bool isRate = _ui->checkBox_Rate->isChecked();
        bool isTemp = _ui->checkBox_Temp->isChecked();
        switch (typeIndex) {
        case 0: {
            //强制失去焦点，否则获取数据有错误
            _ui->tableWidget_Data->setEnabled(false);
            _ui->tableWidget_Data->setEnabled(true);
            int rowNum = _ui->tableWidget_Data->rowCount();
            int colNum = _ui->tableWidget_Data->columnCount();

            int validRowNum = 0;
            bool hasLastNoEmptyRow = true;

            QList<int> columns{ 0, 1 };
            if (isRate) { columns.append(2); }
            if (isTemp) { columns.append(3); }

            for (int i = rowNum - 1; i >= 0; --i) {
                if (validRowNum == 0) {
                    for (auto c : columns) {
                        QTableWidgetItem* item = _ui->tableWidget_Data->item(i, c);
                        if (item == nullptr) continue;
                        auto val = item->text().simplified();
                        if (!val.isEmpty()) {
                            hasLastNoEmptyRow = false;
                            break;
                        }
                    }
                }

                if (!hasLastNoEmptyRow) {
                    for (auto c : columns) {
                        QTableWidgetItem* item = _ui->tableWidget_Data->item(i, c);
                        if (item == nullptr) continue;
                        auto val = item->text().simplified();
                        //if (!checkValue(val, i, c))return false;
                    }
                    ++validRowNum;
                }


                /*for (int j = 0; j < colNum; j++) {

                    QTableWidgetItem* item = _ui->tableWidget_Data->item(i, j);
                    if (item == nullptr) continue;
                    QString value = item->text();

                    if (isRate == false && j == 2) {
                        if (!value.isEmpty()) emptyRow = false;
                        continue;
                    }
                    else if (isTemp == false && j == 3) {
                        continue;
                    }
                    else {
                        if (!checkValue(value, i, j))return false;
                    }
                }*/

            }

            if (validRowNum == 0) {
                QMessageBox::warning(this, tr("StructualApp"), tr("Tabular data for at least one option or suboption\n has either blank or zero valued row(s).\n"));
                return false;
            }

            break;
        }
        case 1: {
            //强制失去焦点，否则获取数据有错误
            _ui->tableWidget_Data->setEnabled(false);
            _ui->tableWidget_Data->setEnabled(true);
            int rowNum = _ui->tableWidget_Data->rowCount();
            int colNum = _ui->tableWidget_Data->columnCount();

            for (int i = 0; i < rowNum; i++) {
                for (int j = 0; j < colNum; j++) {
                    QString value = "";
                    QTableWidgetItem* item = _ui->tableWidget_Data->item(i, j);
                    if (item == nullptr)continue;
                    value = item->text();

                    if (isTemp == false && j == 3) {
                        continue;
                    }
                    else {
                        //if (!checkValue(value, i, j))return false;
                    }
                }
            }
            break;
        }
        case 2: {
            //强制失去焦点，否则获取数据有错误
            _ui->tableWidget_Data->setEnabled(false);
            _ui->tableWidget_Data->setEnabled(true);
            int rowNum = _ui->tableWidget_Data->rowCount();
            int colNum = _ui->tableWidget_Data->columnCount();

            for (int i = 0; i < rowNum; i++) {
                for (int j = 0; j < colNum; j++) {
                    QString value = "";
                    QTableWidgetItem* item = _ui->tableWidget_Data->item(i, j);
                    if (item == nullptr)continue;
                    value = item->text();

                    if (isTemp == false && j == 3) {
                        continue;
                    }
                    else {
                        //if (!checkValue(value, i, j))return false;
                    }
                }
            }
        }
        case 3: {
            //强制失去焦点，否则获取数据有错误
            _ui->tableWidget_JCook->setEnabled(false);
            _ui->tableWidget_JCook->setEnabled(true);
            int colNum = _ui->tableWidget_JCook->columnCount();
            //Johnson-Cook只有一行数据，不判断多行
            for (int j = 0; j < colNum; j++) {
                QString value = "";
                QTableWidgetItem* item = _ui->tableWidget_JCook->item(0, j);
                if (item == nullptr)continue;
                value = item->text();
                //if (!checkValue(value, 0, j))return false;
            }
        }
         case 4:
            //强制失去焦点，否则获取数据有错误
            _ui->tableWidget_Coining->setEnabled(false);
            _ui->tableWidget_Coining->setEnabled(true);
            int colNum = _ui->tableWidget_Coining->columnCount();
            //Coining只有一行数据，不判断多行
            for (int j = 0; j < colNum; j++) {
                QString value = "";
                QTableWidgetItem* item = _ui->tableWidget_Coining->item(0, j);
                if (item == nullptr)continue;
                value = item->text();
                //if (!checkValue(value, 0, j))return false;
            }
        }
        return true;
    }

    bool MaterialPlasticWidget::saveValue()
    {
        if (_materialItem == nullptr)return false;

        Interface::FITKAbaMaterialBehaviorEnum::FITKAbaMaterialPlasticType type;
        switch (_ui->comboBox_Hardening->currentIndex()) {
        case 0:type = Interface::FITKAbaMaterialBehaviorEnum::FITKAbaMaterialPlasticType::PlasticIsoTropic; break;
        case 1:type = Interface::FITKAbaMaterialBehaviorEnum::FITKAbaMaterialPlasticType::PlasticKinematic; break;
        case 2:type = Interface::FITKAbaMaterialBehaviorEnum::FITKAbaMaterialPlasticType::PlasticMultiLinearKinematic; break;
        case 3:type = Interface::FITKAbaMaterialBehaviorEnum::FITKAbaMaterialPlasticType::PlasticJohnsonCook; break;
        case 4:type = Interface::FITKAbaMaterialBehaviorEnum::FITKAbaMaterialPlasticType::PlasticCoining; break;
        }

        _materialItem->setPlasticType(type);

        saveValue(type);
        return true;
    }

    void MaterialPlasticWidget::on_comboBox_Hardening_activated(int index)
    {
        Interface::FITKAbaMaterialBehaviorEnum::FITKAbaMaterialPlasticType type;
        switch (index) {
        case 0:type = Interface::FITKAbaMaterialBehaviorEnum::FITKAbaMaterialPlasticType::PlasticIsoTropic; break;
        case 1:type = Interface::FITKAbaMaterialBehaviorEnum::FITKAbaMaterialPlasticType::PlasticKinematic; break;
        case 2:type = Interface::FITKAbaMaterialBehaviorEnum::FITKAbaMaterialPlasticType::PlasticMultiLinearKinematic; break;
        case 3:type = Interface::FITKAbaMaterialBehaviorEnum::FITKAbaMaterialPlasticType::PlasticJohnsonCook; break;
        case 4:type = Interface::FITKAbaMaterialBehaviorEnum::FITKAbaMaterialPlasticType::PlasticCoining; break;
        }

        changeMaterialHardeningType(type);
    }

    void MaterialPlasticWidget::on_checkBox_Rate_clicked(bool checked)
    {
        Interface::FITKAbaMaterialBehaviorEnum::FITKAbaMaterialPlasticType type;
        switch (_ui->comboBox_Hardening->currentIndex()) {
        case 0:type = Interface::FITKAbaMaterialBehaviorEnum::FITKAbaMaterialPlasticType::PlasticIsoTropic; break;
        case 1:type = Interface::FITKAbaMaterialBehaviorEnum::FITKAbaMaterialPlasticType::PlasticKinematic; break;
        case 2:type = Interface::FITKAbaMaterialBehaviorEnum::FITKAbaMaterialPlasticType::PlasticMultiLinearKinematic; break;
        case 3:type = Interface::FITKAbaMaterialBehaviorEnum::FITKAbaMaterialPlasticType::PlasticJohnsonCook; break;
        case 4:type = Interface::FITKAbaMaterialBehaviorEnum::FITKAbaMaterialPlasticType::PlasticCoining; break;
        }

        changeMaterialRate(type, checked);
    }

    void MaterialPlasticWidget::on_checkBox_Temp_clicked(bool checked)
    {
        Interface::FITKAbaMaterialBehaviorEnum::FITKAbaMaterialPlasticType type;
        switch (_ui->comboBox_Hardening->currentIndex()) {
        case 0:type = Interface::FITKAbaMaterialBehaviorEnum::FITKAbaMaterialPlasticType::PlasticIsoTropic; break;
        case 1:type = Interface::FITKAbaMaterialBehaviorEnum::FITKAbaMaterialPlasticType::PlasticKinematic; break;
        case 2:type = Interface::FITKAbaMaterialBehaviorEnum::FITKAbaMaterialPlasticType::PlasticMultiLinearKinematic; break;
        case 3:type = Interface::FITKAbaMaterialBehaviorEnum::FITKAbaMaterialPlasticType::PlasticJohnsonCook; break;
        case 4:type = Interface::FITKAbaMaterialBehaviorEnum::FITKAbaMaterialPlasticType::PlasticCoining; break;
        }

        changeMaterialTemp(type, checked);
    }

    void MaterialPlasticWidget::initUi()
    {
        if (_materialItem == nullptr)return;

        //初始化界面坚固类型
        QStringList hardenTypes = {};
        hardenTypes<< tr("Isotropic") << tr("Kinematic") << tr("Multilinear-Kinematic") << tr("Jonoson-Cook") <<tr("Swift")/*<< tr("User") << tr("Combined")*/;
        _ui->comboBox_Hardening->addItems(hardenTypes);
        //隐藏Kinematic与Multilinear-Kinematic，数据层无数据（2024-06-17）
        QListView* view = qobject_cast<QListView *>(_ui->comboBox_Hardening->view());
        view->setRowHidden(1, true);
        view->setRowHidden(2, true);

        //TableWidget初始化
        _ui->tableWidget_Data->addTableRowAndItem(0);

        _ui->tableWidget_JCook->addTableRowAndItem(0);

        _ui->tableWidget_Coining->addTableRowAndItem(0);
        //设置为单行模式
        _ui->tableWidget_JCook->setIsAloneRow(true);

        _ui->tableWidget_Coining->setIsAloneRow(true);

        auto type = _materialItem->getPlasticType();
        //更新类型
        changeMaterialHardeningType(type);
        switch (type) {
        case Interface::FITKAbaMaterialBehaviorEnum::PlasticIsoTropic:_ui->comboBox_Hardening->setCurrentIndex(0); break;
        case Interface::FITKAbaMaterialBehaviorEnum::PlasticKinematic:_ui->comboBox_Hardening->setCurrentIndex(1); break;
        case Interface::FITKAbaMaterialBehaviorEnum::PlasticMultiLinearKinematic:_ui->comboBox_Hardening->setCurrentIndex(2); break;
        case Interface::FITKAbaMaterialBehaviorEnum::PlasticJohnsonCook:_ui->comboBox_Hardening->setCurrentIndex(3); break;
        case Interface::FITKAbaMaterialBehaviorEnum::PlasticCoining:_ui->comboBox_Hardening->setCurrentIndex(4); break;
        }
        //更新速度参数
        changeMaterialRate(type, _materialItem->getUseStrainRateDependentData());
        _ui->checkBox_Rate->setChecked(_materialItem->getUseStrainRateDependentData());
        //更新温度
        changeMaterialTemp(type, _materialItem->getUseTemperatureDependentData());
        _ui->checkBox_Temp->setChecked(_materialItem->getUseTemperatureDependentData());

        showValue(type);
    }

    void MaterialPlasticWidget::showValue(Interface::FITKAbaMaterialBehaviorEnum::FITKAbaMaterialPlasticType type)
    {
        switch (type) {
        case Interface::FITKAbaMaterialBehaviorEnum::PlasticIsoTropic:
        case Interface::FITKAbaMaterialBehaviorEnum::PlasticKinematic:
        case Interface::FITKAbaMaterialBehaviorEnum::PlasticMultiLinearKinematic: {
            int rowNum = _materialItem->getNumberOfIsotropicDataRows();

            for (int i = 0; i < rowNum; i++) {
                if (i != 0)_ui->tableWidget_Data->insertRow(i);
                QTableWidgetItem* item = new QTableWidgetItem(QString::number(_materialItem->getIsotropicYieldStress(i)));
                _ui->tableWidget_Data->setItem(i, 0, item);
                item = new QTableWidgetItem(QString::number(_materialItem->getIsotropicPlasticStrain(i)));
                _ui->tableWidget_Data->setItem(i, 1, item);
                item = new QTableWidgetItem(QString::number(_materialItem->getIsotropicRate(i)));
                _ui->tableWidget_Data->setItem(i, 2, item);
                item = new QTableWidgetItem(QString::number(_materialItem->getIsotropicTemperature(i)));
                _ui->tableWidget_Data->setItem(i, 3, item);
            }
            break;
        }
        case Interface::FITKAbaMaterialBehaviorEnum::PlasticJohnsonCook: {
            QTableWidgetItem* item = new QTableWidgetItem(QString::number(_materialItem->getJohnsonCookA()));
            _ui->tableWidget_JCook->setItem(0, 0, item);
            item = new QTableWidgetItem(QString::number(_materialItem->getJohnsonCookB()));
            _ui->tableWidget_JCook->setItem(0, 1, item);
            item = new QTableWidgetItem(QString::number(_materialItem->getJohnsonCookn()));
            _ui->tableWidget_JCook->setItem(0, 2, item);
            item = new QTableWidgetItem(QString::number(_materialItem->getJohnsonCookm()));
            _ui->tableWidget_JCook->setItem(0, 3, item);
            item = new QTableWidgetItem(QString::number(_materialItem->getJohnsonCookMeltingTemp()));
            _ui->tableWidget_JCook->setItem(0, 4, item);
            item = new QTableWidgetItem(QString::number(_materialItem->getJohnsonCookTransitionTemp()));
            _ui->tableWidget_JCook->setItem(0, 5, item);
            break;
        }
        case Interface::FITKAbaMaterialBehaviorEnum::PlasticCoining:{
            QTableWidgetItem* item = new QTableWidgetItem(QString::number(_materialItem->getCoiningYOUNGMD()));
            _ui->tableWidget_Coining->setItem(0, 0, item);
            item = new QTableWidgetItem(QString::number(_materialItem->getCoiningPOISSONR()));
            _ui->tableWidget_Coining->setItem(0, 1, item);
            item = new QTableWidgetItem(QString::number(_materialItem->getCoiningCOEFFICA()));
            _ui->tableWidget_Coining->setItem(0, 2, item);
            item = new QTableWidgetItem(QString::number(_materialItem->getCoiningHARDENN()));
            _ui->tableWidget_Coining->setItem(0, 3, item);
            item = new QTableWidgetItem(QString::number(_materialItem->getCoiningYIELDSST()));
            _ui->tableWidget_Coining->setItem(0, 4, item);
            break;
        }
        }
    }

    void MaterialPlasticWidget::saveValue(Interface::FITKAbaMaterialBehaviorEnum::FITKAbaMaterialPlasticType type)
    {
        if (_materialItem == nullptr)return;
        switch (type) {
        case Interface::FITKAbaMaterialBehaviorEnum::PlasticIsoTropic: {
            //强制失去焦点，否则获取数据有错误
            _ui->tableWidget_Data->setEnabled(false);

            _materialItem->setUseStrainRateDependentData(_ui->checkBox_Rate->isChecked());
            _materialItem->setUseTemperatureDependentData(_ui->checkBox_Temp->isChecked());

            int rowNum = _ui->tableWidget_Data->rowCount();
            

            bool isRate = _ui->checkBox_Rate->isChecked();
            bool isTemp = _ui->checkBox_Temp->isChecked();

            _materialItem->setNumberOfIsoTropicDataRows(rowNum);
             int validRow = 0;
            for (int i = 0; i < rowNum; i++) {

                auto yieldItem = _ui->tableWidget_Data->item(i, 0);
                auto plasticItem = _ui->tableWidget_Data->item(i, 1);
                auto rateItem = _ui->tableWidget_Data->item(i, 2);
                auto tempItem = _ui->tableWidget_Data->item(i, 3);

                if (yieldItem == nullptr || plasticItem == nullptr || rateItem == nullptr || tempItem == nullptr) continue;
                if (yieldItem->text().isEmpty()
                    || plasticItem->text().isEmpty()
                    || (isRate && rateItem->text().isEmpty())
                    || (isTemp &&  tempItem->text().isEmpty())) continue;

                _materialItem->setIsotropicYieldStess(yieldItem->text().toDouble(), i);
                _materialItem->setIsotropicPlasticStrain(plasticItem->text().toDouble(), i);
                if (isRate) { _materialItem->setIsotropicRate(rateItem->text().toDouble(), i); }
                if (isTemp) { _materialItem->setIsotropicTemperature(tempItem->text().toDouble(), i); }
                ++validRow;
                /*QTableWidgetItem* item = nullptr;
                double value = 0;

                item = _ui->tableWidget_Data->item(i, 0);
                if (!item)value = 0;
                else value = item->text().toDouble();
                _materialItem->setIsotropicYieldStess(value, i);

                item = _ui->tableWidget_Data->item(i, 1);
                if (!item)value = 0;
                else value = item->text().toDouble();
                _materialItem->setIsotropicPlasticStrain(value, i);

                //如果速度参数未使用，将其至为0
                if (_ui->checkBox_Rate->isChecked()) {
                    item = _ui->tableWidget_Data->item(i, 2);
                    if (!item)value = 0;
                    else value = item->text().toDouble();
                }
                else value = 0;
                _materialItem->setIsotropicRate(value, i);

                //如果温度参数未使用，将其值为0
                if (_ui->checkBox_Temp->isChecked()) {
                    item = _ui->tableWidget_Data->item(i, 3);
                    if (!item)value = 0;
                    else value = item->text().toDouble();
                }
                else value = 0;
                _materialItem->setIsotropicTemperature(value, i);*/
            }
            _materialItem->setNumberOfIsoTropicDataRows(validRow);
            break;
        }
        case Interface::FITKAbaMaterialBehaviorEnum::PlasticKinematic: {
            break;
        }
        case Interface::FITKAbaMaterialBehaviorEnum::PlasticMultiLinearKinematic: {
            break;
        }
        case Interface::FITKAbaMaterialBehaviorEnum::PlasticJohnsonCook: {

            //强制失去焦点，否则获取数据有错误
            _ui->tableWidget_JCook->setEnabled(false);

            //JohnsonCook模式下设置rate为false
            _materialItem->setUseStrainRateDependentData(false);
            //JohnsonCook模式下设置Temp为false
            _materialItem->setUseTemperatureDependentData(false);

            QTableWidgetItem* item = nullptr;
            double value = 0;

            item = _ui->tableWidget_JCook->item(0, 0);
            if (!item)value = 0;
            else value = item->text().toDouble();
            _materialItem->setJohnsonCookA(value);

            item = _ui->tableWidget_JCook->item(0, 1);
            if (!item)value = 0;
            else value = item->text().toDouble();
            _materialItem->setJohnsonCookB(value);

            item = _ui->tableWidget_JCook->item(0, 2);
            if (!item)value = 0;
            else value = item->text().toDouble();
            _materialItem->setJohnsonCookn(value);

            item = _ui->tableWidget_JCook->item(0, 3);
            if (!item)value = 0;
            else value = item->text().toDouble();
            _materialItem->setJohnsonCookm(value);

            item = _ui->tableWidget_JCook->item(0, 4);
            if (!item)value = 0;
            else value = item->text().toDouble();
            _materialItem->setJohnsonCookMeltingTemp(value);

            item = _ui->tableWidget_JCook->item(0, 5);
            if (!item)value = 0;
            else value = item->text().toDouble();
            _materialItem->setJohnsonCookTransitionTemp(value);
            break;
        }           
        case Interface::FITKAbaMaterialBehaviorEnum::PlasticCoining: {
            //强制失去焦点，否则获取数据有错误
            _ui->tableWidget_JCook->setEnabled(false);

            //JohnsonCook模式下设置rate为false
            _materialItem->setUseStrainRateDependentData(false);
            //JohnsonCook模式下设置Temp为false
            _materialItem->setUseTemperatureDependentData(false);

            QTableWidgetItem* item = nullptr;
            double value = 0;

            item = _ui->tableWidget_Coining->item(0, 0);
            if (!item)value = 0;
            else value = item->text().toDouble();
            _materialItem->setCoiningYOUNGMD(value);

            item = _ui->tableWidget_Coining->item(0, 1);
            if (!item)value = 0;
            else value = item->text().toDouble();
            _materialItem->setCoiningPOISSONR(value);

            item = _ui->tableWidget_Coining->item(0, 2);
            if (!item)value = 0;
            else value = item->text().toDouble();
            _materialItem->setCoiningCOEFFICA(value);

            item = _ui->tableWidget_Coining->item(0, 3);
            if (!item)value = 0;
            else value = item->text().toDouble();
            _materialItem->setCoiningHARDENN(value);

            item = _ui->tableWidget_Coining->item(0, 4);
            if (!item)value = 0;
            else value = item->text().toDouble();
            _materialItem->setCoiningYIELDSST(value);
        }
        }
    }

    void MaterialPlasticWidget::changeMaterialHardeningType(Interface::FITKAbaMaterialBehaviorEnum::FITKAbaMaterialPlasticType type)
    {
        //隐藏所有的TableWidget
        _ui->groupBox_Data->hide();
        _ui->groupBox_JCook->hide();
        _ui->groupBox_Coining->hide();

        switch (type) {
        case Interface::FITKAbaMaterialBehaviorEnum::PlasticIsoTropic: {
            _ui->checkBox_Rate->show();
            _ui->checkBox_Temp->show();
            changeMaterialRate(type, _ui->checkBox_Rate->isChecked());
            changeMaterialTemp(type, _ui->checkBox_Temp->isChecked());
            _ui->groupBox_Data->show();
            break;
        }
        case Interface::FITKAbaMaterialBehaviorEnum::PlasticKinematic: {
            _ui->checkBox_Rate->show();
            _ui->checkBox_Temp->show();
            changeMaterialRate(type, false);
            changeMaterialTemp(type, _ui->checkBox_Temp->isChecked());
            _ui->groupBox_Data->show();
            break;
        }
        case Interface::FITKAbaMaterialBehaviorEnum::PlasticMultiLinearKinematic: {
            _ui->checkBox_Rate->show();
            _ui->checkBox_Temp->show();
            changeMaterialRate(type, false);
            changeMaterialTemp(type, _ui->checkBox_Temp->isChecked());
            _ui->groupBox_Data->show();
            break;
        }
        case Interface::FITKAbaMaterialBehaviorEnum::PlasticJohnsonCook: {
            _ui->checkBox_Rate->hide();
            _ui->checkBox_Temp->hide();
            changeMaterialRate(type, false);
            changeMaterialTemp(type, false);
            _ui->groupBox_JCook->show();
            break;
        }
        case Interface::FITKAbaMaterialBehaviorEnum::PlasticCoining: {
            _ui->checkBox_Rate->hide();
            _ui->checkBox_Temp->hide();
            changeMaterialRate(type, false);
            changeMaterialTemp(type, false);
            _ui->groupBox_Coining->show();
            break;
        }
        }
    }

    void MaterialPlasticWidget::changeMaterialTemp(Interface::FITKAbaMaterialBehaviorEnum::FITKAbaMaterialPlasticType type, bool isTemp)
    {
        switch (type) {
        case Interface::FITKAbaMaterialBehaviorEnum::PlasticIsoTropic: {
            _ui->checkBox_Temp->setEnabled(true);
            if (isTemp) _ui->tableWidget_Data->showColumn(3);
            else _ui->tableWidget_Data->hideColumn(3);
            break;
        }
        case Interface::FITKAbaMaterialBehaviorEnum::PlasticKinematic: {
            _ui->checkBox_Temp->setEnabled(true);
            if (isTemp) _ui->tableWidget_Data->showColumn(3);
            else _ui->tableWidget_Data->hideColumn(3);
            break;
        }
        case Interface::FITKAbaMaterialBehaviorEnum::PlasticMultiLinearKinematic: {
            _ui->checkBox_Temp->setEnabled(true);
            if (isTemp) _ui->tableWidget_Data->showColumn(3);
            else _ui->tableWidget_Data->hideColumn(3);
            break;
        }
        case Interface::FITKAbaMaterialBehaviorEnum::PlasticJohnsonCook: {
            break;
        }
        case Interface::FITKAbaMaterialBehaviorEnum::PlasticCoining: {
            break;
        }
    }
    }

    void MaterialPlasticWidget::changeMaterialRate(Interface::FITKAbaMaterialBehaviorEnum::FITKAbaMaterialPlasticType type, bool isRate)
    {
        switch (type) {
        case Interface::FITKAbaMaterialBehaviorEnum::PlasticIsoTropic: {

            _ui->checkBox_Rate->setEnabled(true);
            if (isRate)_ui->tableWidget_Data->showColumn(2);
            else _ui->tableWidget_Data->hideColumn(2);
            break;
        }
        case Interface::FITKAbaMaterialBehaviorEnum::PlasticKinematic: {
            _ui->checkBox_Rate->setChecked(false);
            _ui->checkBox_Rate->setEnabled(false);
            _ui->tableWidget_Data->hideColumn(2);
            _ui->tableWidget_Data->item(0, 2)->setText("0");
            break;
        }
        case Interface::FITKAbaMaterialBehaviorEnum::PlasticMultiLinearKinematic: {
            _ui->checkBox_Rate->setChecked(false);
            _ui->checkBox_Rate->setEnabled(false);
            _ui->tableWidget_Data->hideColumn(2);
            _ui->tableWidget_Data->item(0, 2)->setText("0");
            break;
        }
        case Interface::FITKAbaMaterialBehaviorEnum::PlasticJohnsonCook: {
            break;
        }
        case Interface::FITKAbaMaterialBehaviorEnum::PlasticCoining: {
            break;
        }

        }
    }

    // 提取数值部分
    QString MaterialPlasticWidget::extractNumberPart(const QString &text)
    {
        QString numberPart = text;

        // 查找单位的开始位置（例如，查找数字后面的空格或字母等）
        int unitStartIndex = text.indexOf(QRegExp("[^0-9\\.]"));

        // 如果找到了单位部分，截取数值部分
        if (unitStartIndex != -1) {
            numberPart = text.left(unitStartIndex).trimmed();  // 提取数值部分并去掉空格
        }

        return numberPart;
    }


}  // namespace GUI
